package com.youchuang.action.main;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionSupport;
import com.youchuang.action.BaseAction;
import com.youchuang.bean.Book;
import com.youchuang.service.MainService;

import net.sf.json.JSONArray;

/**
 * 根据用户输入的模糊字查询图书列表
 * 
 * @author Administrator
 *
 */
@Namespace(value = "/main")
@ParentPackage("shopping-default")
public class SearchBookListAction extends BaseAction {
	private Logger logger = Logger.getLogger(SearchBookListAction.class.getSimpleName());
	private String name;
	private List<Book> books;
	
	@Resource
	private MainService mainService;

	@Action(value = "searchBookList", results = {
			@Result(name = ActionSupport.SUCCESS, location = "/WEB-INF/jsp/main/search_book_list.jsp") })
	public String execute() throws Exception {
		logger.info("excetion is execute");

		books = mainService.findBookLimmitByProductName(name);

		logger.info("response json books = " + JSONArray.fromObject(books).toString());
		return ActionSupport.SUCCESS;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<Book> getBooks() {
		return books;
	}

	public void setBooks(List<Book> books) {
		this.books = books;
	}

}
